#include "stdafx.h"

#include "Player/PlayerContainer.h"
#include "Player/Player.h"
#include "RunningState.h"
#include "terrain/Terrain.h"
#include "core/game.h"
#include "network/Communicator.h"
#include "input/InputManager.h"
#include "pathing/PathingManager.h"
#include "Obj/ObjContainer.h"

RunningState::RunningState() : playerContainer(nullptr), inited(false)    
{
    type = RUNNING;
}

RunningState::~RunningState()
{

}

void RunningState::update(float dt)
{
    /*if ( input->isKeyClicked(GLFW_KEY_SPACE) ) 
        queuedState = PENDING;*/
	playerContainer->localPlayer->input->update();
	Game::getInstance()->communicator->update(dt, type);
    playerContainer->update(dt);
	ObjContainer::getInstance()->update(dt);
	PathingManager::getInstance()->update(dt);
}

void RunningState::init()
{
	inited = true;
}

void RunningState::activate()
{
    queuedState = NULL_STATE;
	if (!inited) // init on first activation 
		init();
}

void RunningState::idle() {

}

void RunningState::initPlayers(std::vector<Packets::PlayerStartInfo> & playerStartInfoList, int localId) {
	assert(!playerContainer);
	playerContainer = new PlayerContainer(playerStartInfoList, localId);
}